package com.wangzaiplus.test.juc.thread;

/**
 * @ClassName SynDemo1
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/28 18:05
 * @Version V1.0
 **/
public class SynDemo2  implements  Runnable{
    static SynDemo2 instance = new SynDemo2();
    static int i=0;


    @Override
    public void run() {
        synchronized (instance){
            for (int j = 0; j <10000; j++) {
                i++;
            }
        }
    }


    public static void main(String[] args) throws InterruptedException {
         Thread t1=new Thread(instance);
        Thread t2=new Thread(instance);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
}
